﻿using System;
using ePlanet.ArchiveBorrow.Models;
using ePlanet.ArchiveBorrow.Services;
using ePlanet.ArchiveMange.Enum;
using Microsoft.Practices.Unity;

namespace Web.Views.ArchiveBorrow.ArchiveBorrowApprove
{
    public partial class ArchiveBorrowApproveBase : PageBase
    {
        [Dependency]
        public IArchiveBorrowService m_IArchiveBorrowService
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Jump();
        }

        private void Jump()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["DataID"]))
            {
                Guid archiveBorrowDataID = new Guid(Request.QueryString["DataID"]);
                ArchiveBorrowModel model = this.m_IArchiveBorrowService.GetSingleArchiveBorrowModelByDataID(archiveBorrowDataID);
                if (model != null && model.ARCHIVEBORROW.Rows.Count > 0)
                {
                    ArchiveBaseType archiveType = (ArchiveBaseType)(int)model.ARCHIVEBORROW[0].ARCHIVETYPEID;
                    this.Rediret(archiveType, Request.QueryString["DataID"]);
                }
                else
                {
                    Response.Write("该数据文档类型错误！");
                }
            }
            else
            {
                Response.Write("参数DataID不能为空！");
            }
        }

        private void Rediret(ArchiveBaseType archiveType, string dataID)
        {
            string urlFormat = "{0}?DataID=" + dataID;
            switch (archiveType)
            {
                case ArchiveBaseType.Account:
                    Response.Redirect(string.Format(urlFormat, "AccountArchiveApprove.aspx"));
                    break;
                case ArchiveBaseType.AudioVedio:
                    Response.Redirect(string.Format(urlFormat, "AudioVedioApprove.aspx"));
                    break;
                case ArchiveBaseType.BulidProject:
                    Response.Redirect(string.Format(urlFormat, "BulidProjectApprove.aspx"));
                    break;
                case ArchiveBaseType.CDKind:
                    Response.Redirect(string.Format(urlFormat, "CDKindApprove.aspx"));
                    break;
                case ArchiveBaseType.Document:
                    Response.Redirect(string.Format(urlFormat, "DocumentArchiveApprove.aspx"));
                    break;
                case ArchiveBaseType.Equipment:
                    Response.Redirect(string.Format(urlFormat, "EquipmentApprove.aspx"));
                    break;
                case ArchiveBaseType.OliSearch:
                    Response.Redirect(string.Format(urlFormat, "OliSearchApprove.aspx"));
                    break;
                case ArchiveBaseType.RealKind:
                    Response.Redirect(string.Format(urlFormat, "RealKindApprove.aspx"));
                    break;
                case ArchiveBaseType.Technology:
                    Response.Redirect(string.Format(urlFormat, "TechnologyApprove.aspx"));
                    break;
                default:
                    Alert("未知的文档类型！");
                    break;
            }
        }
    }
}